using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ProxyServer.Entities;
using ProxyServer.EntityFrameworkCore.ValueConverts;
using Yarp.ReverseProxy.Configuration;

namespace ProxyServer.EntityFrameworkCore.Sqlite;

public class ProxyConfigSnapshotEntityTypeConfiguration : IEntityTypeConfiguration<ProxyConfigSnapshotEntity>
{
    public void Configure(EntityTypeBuilder<ProxyConfigSnapshotEntity> builder)
    {
        builder.HasKey(x => x.Id);
        builder.Property(x => x.Routes).HasConversion(new JsonStringValueConverter<List<RouteConfig>>([]));
        builder.Property(x => x.Clusters).HasConversion(new JsonStringValueConverter<List<ClusterConfig>>([]));
        builder.Property(x => x.AppliedAt).HasConversion(DateTimeOffsetToTicksValueConverter.Singleton);
        builder.Property(x => x.RemovedAt).HasConversion(DateTimeOffsetToTicksValueConverter.Singleton);
    }
}